package com.ithema.controller;

import com.ithema.entity.Result;
import com.ithema.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileUploadController {

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws IOException {
        //文件的内容存储到本地磁盘上
        String origainalFileName = file.getOriginalFilename();
        //保证文件名字都是唯一的
        String s = UUID.randomUUID().toString() + origainalFileName.substring(origainalFileName.lastIndexOf("."));
        //file.transferTo(new File("C:\\Users\\殷云飞\\Desktop\\files"+s));
        String url= AliOssUtil.uploasFile(s, file.getInputStream());
        return Result.success(url);
    }

}
